<!DOCTYPE html>
<html>
<head>
  <title>Balancer.java</title>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <link rel='stylesheet' type='text/css' href='../../../../../../coverage.css'/>
  <link rel='shortcut icon' type='image/png' href='../../../../../../logo.png'/>
  <script type='text/javascript' src='../../../../../../coverage.js'></script>
  <script type='text/javascript' src='../../../../../../prettify.js'></script>
</head>
<body onload='prettyPrint()'>
  <table cellpadding='0' cellspacing='1'>
    <caption>igraph_client_java/src/main/java/com/taobao/igraph/vipserver/client/core/Balancer.java</caption>
    <tr>
      <td class='line'>1</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>package com.taobao.igraph.vipserver.client.core;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td><pre class='imports prettyprint' onclick='showHideLines(this)'><div>import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;

import com.ali.unit.rule.Router;
import com.taobao.igraph.vipserver.client.utils.UtilAndComs;
</div><span>import ...</span></pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>/**
 * Innovated By: Xuanyin.zy@taobao.com
 * &lt;p/>
 * 2014-21-08 13:27
 */</div><span>/*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>21</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>public class Balancer {</pre></td>
    </tr>
    <tr>
      <td class='line'>22</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>	public static class RR {</pre></td>
    </tr>
    <tr>
      <td class='line'>23</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		private static ConcurrentMap&lt;String, AtomicLong> POS_MAP = new ConcurrentHashMap&lt;String, AtomicLong>();</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>25</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		public static List&lt;Host> selectAll(Domain dom) {</pre></td>
    </tr>
    <tr>
      <td class='line'>26</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			List&lt;Host> hosts = dom.getHosts();</pre></td>
    </tr>
    <tr>
      <td class='line'>27</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (CollectionUtils.isEmpty(hosts)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>28</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				throw new IllegalStateException("no host to srv for dom: "</pre></td>
    </tr>
    <tr>
      <td class='line'>29</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						+ dom.getName());</pre></td>
    </tr>
    <tr>
      <td class='line'>30</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>32</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			return filterAndDuplicate(hosts);</pre></td>
    </tr>
    <tr>
      <td class='line'>33</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>35</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		public static Host selectHost(Domain dom) {</pre></td>
    </tr>
    <tr>
      <td class='line'>36</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			AtomicLong pos = POS_MAP.get(dom.getKey());</pre></td>
    </tr>
    <tr>
      <td class='line'>37</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (pos == null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>38</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				POS_MAP.putIfAbsent(dom.getKey(),</pre></td>
    </tr>
    <tr>
      <td class='line'>39</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						new AtomicLong(RandomUtils.nextInt(Short.MAX_VALUE)));</pre></td>
    </tr>
    <tr>
      <td class='line'>40</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				pos = POS_MAP.get(dom.getKey());</pre></td>
    </tr>
    <tr>
      <td class='line'>41</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>43</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			List&lt;Host> hosts = selectAll(dom);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>45</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			MotionFlow.enter(dom.getName());</pre></td>
    </tr>
    <tr>
      <td class='line'>46</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			return hosts.get((int) (pos.incrementAndGet() % hosts.size()));</pre></td>
    </tr>
    <tr>
      <td class='line'>47</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>49</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		public static List&lt;Host> nothing(Domain dom) {</pre></td>
    </tr>
    <tr>
      <td class='line'>50</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			return dom.getHosts();</pre></td>
    </tr>
    <tr>
      <td class='line'>51</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr>
      <td class='line'>52</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>	}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>54</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>	public static class Unit {</pre></td>
    </tr>
    <tr>
      <td class='line'>55</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		private static ConcurrentMap&lt;String, DomEntry> DOM_ENTRY_MAP = new ConcurrentHashMap&lt;String, DomEntry>();</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>57</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		private static class DomEntry {</pre></td>
    </tr>
    <tr>
      <td class='line'>58</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			public ConcurrentMap&lt;String, UnitEntry> unitEntryMap = new ConcurrentHashMap&lt;String, UnitEntry>();</pre></td>
    </tr>
    <tr>
      <td class='line'>59</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>61</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		private static class UnitEntry {</pre></td>
    </tr>
    <tr>
      <td class='line'>62</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			private List&lt;Host> hosts = new ArrayList&lt;Host>();</pre></td>
    </tr>
    <tr>
      <td class='line'>63</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			private AtomicLong pos = new AtomicLong(</pre></td>
    </tr>
    <tr>
      <td class='line'>64</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					RandomUtils.nextInt(Short.MAX_VALUE));</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>66</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			public List&lt;Host> getHosts() {</pre></td>
    </tr>
    <tr>
      <td class='line'>67</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				return new ArrayList&lt;Host>(hosts);</pre></td>
    </tr>
    <tr>
      <td class='line'>68</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr>
      <td class='line'>69</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>71</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		public static List&lt;Host> selectAll(Domain dom, long userId) {</pre></td>
    </tr>
    <tr>
      <td class='line'>72</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			List&lt;Host> hosts = getUnitEntry(dom, userId).getHosts();</pre></td>
    </tr>
    <tr>
      <td class='line'>73</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (CollectionUtils.isEmpty(hosts)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>74</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				throw new IllegalStateException("no host to srv for dom: "</pre></td>
    </tr>
    <tr>
      <td class='line'>75</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						+ dom.getName() + "of userId: " + userId);</pre></td>
    </tr>
    <tr>
      <td class='line'>76</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>78</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			return filterAndDuplicate(hosts);</pre></td>
    </tr>
    <tr>
      <td class='line'>79</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>81</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		public static Host selectHost(Domain dom, long userId) {</pre></td>
    </tr>
    <tr>
      <td class='line'>82</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			UnitEntry unitEntry = getUnitEntry(dom, userId);</pre></td>
    </tr>
    <tr>
      <td class='line'>83</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			List&lt;Host> hosts = selectAll(dom, userId);</pre></td>
    </tr>
    <tr>
      <td class='line'>84</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (CollectionUtils.isEmpty(hosts)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>85</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				throw new IllegalStateException("no host to srv for dom: "</pre></td>
    </tr>
    <tr>
      <td class='line'>86</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						+ dom.getName() + "of userId: " + userId);</pre></td>
    </tr>
    <tr>
      <td class='line'>87</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>89</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			MotionFlow.enter(dom.getName());</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>91</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			return hosts.get((int) (unitEntry.pos.incrementAndGet() % hosts</pre></td>
    </tr>
    <tr>
      <td class='line'>92</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					.size()));</pre></td>
    </tr>
    <tr>
      <td class='line'>93</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>95</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		public static List&lt;Host> nothing(Domain dom, long userId) {</pre></td>
    </tr>
    <tr>
      <td class='line'>96</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			return getUnitEntry(dom, userId).getHosts();</pre></td>
    </tr>
    <tr>
      <td class='line'>97</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>99</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		private static UnitEntry getUnitEntry(Domain dom, long userId) {</pre></td>
    </tr>
    <tr>
      <td class='line'>100</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			DomEntry domEntry = DOM_ENTRY_MAP.get(dom.getKey());</pre></td>
    </tr>
    <tr>
      <td class='line'>101</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (domEntry == null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>102</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				UnitMapGenerator listener = new UnitMapGenerator(dom);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>104</td><td>&nbsp;</td>
      <td><pre class='comment'>				// synchronously update at first time</pre></td>
    </tr>
    <tr>
      <td class='line'>105</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				listener.ipChanged(dom.getHosts());</pre></td>
    </tr>
    <tr>
      <td class='line'>106</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				domEntry = DOM_ENTRY_MAP.get(dom.getKey());</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>108</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				VIPClient.listen(dom.getName(), listener);</pre></td>
    </tr>
    <tr>
      <td class='line'>109</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>111</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			String unit = Router.getUnitByUserId(userId);</pre></td>
    </tr>
    <tr>
      <td class='line'>112</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (StringUtils.isEmpty(unit)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>113</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				throw new IllegalArgumentException(</pre></td>
    </tr>
    <tr>
      <td class='line'>114</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						"unable to figure unit for userId:" + userId);</pre></td>
    </tr>
    <tr>
      <td class='line'>115</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>117</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			UnitEntry unitEntry = domEntry.unitEntryMap.get(unit);</pre></td>
    </tr>
    <tr>
      <td class='line'>118</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (unitEntry == null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>119</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				throw new IllegalArgumentException("no ip matches unit: "</pre></td>
    </tr>
    <tr>
      <td class='line'>120</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						+ unit + "of userId: " + userId);</pre></td>
    </tr>
    <tr>
      <td class='line'>121</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>123</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			return unitEntry;</pre></td>
    </tr>
    <tr>
      <td class='line'>124</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>126</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		private static class UnitMapGenerator implements HostListener {</pre></td>
    </tr>
    <tr>
      <td class='line'>127</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			Domain dom;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>129</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			public UnitMapGenerator(Domain dom) {</pre></td>
    </tr>
    <tr>
      <td class='line'>130</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				this.dom = dom;</pre></td>
    </tr>
    <tr>
      <td class='line'>131</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>133</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			@Override</pre></td>
    </tr>
    <tr>
      <td class='line'>134</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			public void ipChanged(List&lt;Host> hosts) {</pre></td>
    </tr>
    <tr>
      <td class='line'>135</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				DomEntry domEntry = new DomEntry();</pre></td>
    </tr>
    <tr>
      <td class='line'>136</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				for (Host host : hosts) {</pre></td>
    </tr>
    <tr>
      <td class='line'>137</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					String unit = host.getUnit();</pre></td>
    </tr>
    <tr>
      <td class='line'>138</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					if (StringUtils.isEmpty(unit)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>139</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						unit = UtilAndComs.CENTER_UNIT;</pre></td>
    </tr>
    <tr>
      <td class='line'>140</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>142</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					UnitEntry unitEntry = domEntry.unitEntryMap.get(unit);</pre></td>
    </tr>
    <tr>
      <td class='line'>143</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					if (unitEntry == null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>144</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						domEntry.unitEntryMap</pre></td>
    </tr>
    <tr>
      <td class='line'>145</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>								.putIfAbsent(unit, new UnitEntry());</pre></td>
    </tr>
    <tr>
      <td class='line'>146</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>						unitEntry = domEntry.unitEntryMap.get(unit);</pre></td>
    </tr>
    <tr>
      <td class='line'>147</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>149</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>					unitEntry.hosts.add(host);</pre></td>
    </tr>
    <tr>
      <td class='line'>150</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>152</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				DOM_ENTRY_MAP.put(dom.getKey(), domEntry);</pre></td>
    </tr>
    <tr>
      <td class='line'>153</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr>
      <td class='line'>154</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr>
      <td class='line'>155</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>	}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>157</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>	private static List&lt;Host> filterAndDuplicate(List&lt;Host> hosts) {</pre></td>
    </tr>
    <tr>
      <td class='line'>158</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		List&lt;Host> duplicated = new ArrayList&lt;Host>();</pre></td>
    </tr>
    <tr>
      <td class='line'>159</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		for (Host host : hosts) {</pre></td>
    </tr>
    <tr>
      <td class='line'>160</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			if (!host.isValid()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>161</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				continue;</pre></td>
    </tr>
    <tr>
      <td class='line'>162</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>164</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			for (int i = 0; i &lt; host.getWeight(); i++) {</pre></td>
    </tr>
    <tr>
      <td class='line'>165</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>				duplicated.add(host);</pre></td>
    </tr>
    <tr>
      <td class='line'>166</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>			}</pre></td>
    </tr>
    <tr>
      <td class='line'>167</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>169</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>		return duplicated;</pre></td>
    </tr>
    <tr>
      <td class='line'>170</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>	}</pre></td>
    </tr>
    <tr>
      <td class='line'>171</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>}</pre></td>
    </tr>
  </table>
</body>
</html>
